package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-14
 * Time: 11:14
 */
//多态
class Shape{
    //...
    public int a = 1;

    public void draw(){
        System.out.println("画图形");
    }

}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("⏹");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("○");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀");
        System.out.println("🌂");
    }
}
public class Test2 {

    public static void main3(String[] args) {
        Shape shape = new Shape();
        System.out.println(shape);
    }
    public static void drawMap3(){
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Shape[] shapes = {cycle, rect, cycle, rect, flower};

        for (Shape shape:shapes) {
            shape.draw();
        }
    }
    public static void drawMap2(){
         Rect rect = new Rect();
         Cycle cycle = new Cycle();
         Flower flower = new Flower();
         String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
         for (String shape : shapes) {
             if (shape.equals("cycle")) {
                 cycle.draw();
             } else if (shape.equals("rect")) {
                 rect.draw();
             } else if (shape.equals("flower")) {
                 flower.draw();
             }
         }
    }

    public static void main2(String[] args) {
        drawMap3();
    }
    public static void drawMap1(Shape shape){
        shape.draw();
    }
    public static void main1(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        drawMap1(rect);
        drawMap1(cycle);
        drawMap1(flower);
    }
}
